<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<!-- 设置语言为中文 -->
		<meta http-equiv="Content-Language" content="zh-cn" />
		<!-- 禁止百度转码 -->
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<!-- 是否开启cleartype显示效果 -->
		<meta http-equiv="cleartype" content="on">
		<meta name="skype_toolbar" content="skype_toolbar_parser_compatible">
		<!-- 优先使用最新的chrome版本 -->
		<meta http-equiv="X-UA-Compatible" content="chrome=1" />
		<!-- 启用360浏览器的极速模式(webkit) -->
		<meta name="renderer" content="webkit">
		<!-- 避免IE使用兼容模式 -->
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<!-- 针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓 -->
		<meta name="HandheldFriendly" content="true">
		<!-- 设置手持设备支持 -->
		<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
		<meta content="yes" name="apple-mobile-web-app-capable">
		<meta content="black" name="apple-mobile-web-app-status-bar-style">
		<meta content="telephone=no" name="format-detection">
		<title>NSC</title>
		<link type="favicon" rel="shortcut icon" href="favicon.ico" />
		<link rel="stylesheet" href="https://google-api.ac.cn/cdn/jQueryWeUi/css/jquery-weui.css" />
		<link rel="stylesheet" href="https://google-api.ac.cn/cdn/jQueryWeUi/css/weui.css" />
		<link rel="stylesheet" href="css/style.css" />
		<style>
			.weui-btn_primary {
				background-color: rgb(0, 176, 124)!important;
				border: 1px solid rgb(0, 176, 124)!important;
				color: white!important;
			}
			
			.unlogin-main .weui-input {
				text-align: initial!important;
			}
			
			.weui-input::-webkit-input-placeholder {
				text-align: initial!important;
				color: rgb(153, 153, 153)!important;
			}
			
			.weui-input::-moz-placeholder {
				text-align: initial!important;
				color: rgb(153, 153, 153)!important;
			}
			
			.weui-input::-ms-input-placeholder {
				text-align: initial!important;
				color: rgb(153, 153, 153)!important;
			}
		</style>
	</head>

	<body>
		<div id="app">
			<div class="overlay">
				<div class="overlay-content scrolling unlogin">
					<div class="unlogin-bg-wrapper"></div>
					<div class="unlogin-wrapper">
						<div class="logo">
							<img src="img/logo.png" alt="">
						</div>
						<div class="weui-cells f15 unlogin-main">
							<div class="weui-cell">
								<div class="weui-cell__bd">
									<input class="weui-input" type="email" placeholder="登录帐号" maxlength="50" id="username">
								</div>
							</div>
							<div class="weui-cell">
								<div class="weui-cell__bd">
									<input class="weui-input" v-bind:type="pwdType" placeholder="登录密码" maxlength="20" id="password">
								</div>
								<img v-bind:src="seePwd" v-on:click="er()" style="position: absolute;right: 0;height: 20px;width:20px;top: 10px;cursor: pointer;" />
							</div>
							<div class="weui-cell">
								<div class="weui-cell__bd">
									<input class="weui-input" v-bind:type="pwdType2" placeholder="确认登录密码" maxlength="20" id="password2">
								</div>
								<img v-bind:src="seePwd2" v-on:click="er2()" style="position: absolute;right: 0;height: 20px;width:20px;top: 10px;cursor: pointer;" />
							</div>
							<div class="weui-cell">
								<div class="weui-cell__bd">
									<input class="weui-input" type="email" placeholder="推荐人用户名/邀请码（必填）" maxlength="50" id="recommendedUserName">
								</div>
							</div>
							<div class="weui-agree">
								<input id="phoneAgree" type="checkbox" class="weui-agree__checkbox">
								<span class="weui-agree__text">
			                    <label>阅读并同意</label><a href="javascript:;" class="open-popup" data-target="#text" v-on:click="popup()">《用户协议》</a>
			                </span>
							</div>
						</div>
						<div class="unlogin-btn">
							<button class="weui-btn weui-btn_primary button-fix" v-on:click="register()">注册</button>
						</div>
					</div>
				</div>
			</div>
			<div id="text" class="weui-popup__container">
				<div class="weui-popup__overlay"></div>
				<div class="weui-popup__modal">
					<div class="Protocol">
						<span v-html="loadByConfigCodes" v-if="loadByConfigCodes"></span>
						<span v-else>暂无注册协议</span>
						<a href="javascript:;" @click="checked()" class="weui-btn weui-btn_primary close-popup">了解并同意</a>
					</div>
				</div>
			</div>
		</div>
	</body>
	<script src="https://google-api.ac.cn/cdn/jquery/3.3.1/jquery.min.js"></script>
	<script src="https://google-api.ac.cn/cdn/vue/2.5.17/vue.min.js"></script>
	<script src="https://google-api.ac.cn/cdn/jQueryWeUi/js/jquery-weui.min.js"></script>
	<script src="js/jsencrypt.js"></script>
	<script>
		function rsaEncrypt(text) {
			var pubkey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmWVV+6bz66H6B0LXsfK5lnbADSB5PTJPepJ4H/hbgQTtw3MdMisfsDLDHWfl0E9d50PIchtoUZcuZimBykCB06zZXijDpTEQSP4ktGeUfOkLBThbRi/ee9smOvybQ7kzZwRnEcFL6TNGB/qAEbRCqcROKE4Rm7G3ToWQLOCbYcwIDAQAB";
			// java后台生成的
			var encrypt = new JSEncrypt();
			encrypt.setPublicKey(pubkey);
			// 加密
			return encrypt.encrypt(text)
		}
		let ip = "http://47.75.113.229";
		var vm = new Vue({
			el: '#app',
			data: {
				loadByConfigCodes: [],
				seePwd: 'img/WithdrawCash1.png',
				doSeePwd: false,
				pwdType: "password",
				seePwd2: 'img/WithdrawCash1.png',
				doSeePwd2: false,
				pwdType2: "password"
			},
			beforeCreate() {
				_this = this;
			},
			created() {

			},
			mounted() {
				var inviteCode = getQueryValue("inviteCode");
				$("#recommendedUserName").val(inviteCode);
			},
			methods: {
				popup: function() {
					let loadByConfigCodes = {
						"configCodes": "GVRP"
					}
					$.ajax({
						type: "POST",
						url: ip + '/cms/webconfig/loadByConfigCodes.m',
						data: loadByConfigCodes,
						success: function(data) {
							_this.loadByConfigCodes = data.result.GVRP;
						},
						error: function() {

						}
					})
				},
				er: function() {
					if(!this.doSeePwd) {
						this.seePwd = 'img/WithdrawCash2.png';
						this.doSeePwd = true;
						this.pwdType = 'email';
					} else {
						this.seePwd = 'img/WithdrawCash1.png';
						this.doSeePwd = false;
						this.pwdType = 'password';
					}
				},
				er2: function() {
					if(!this.doSeePwd2) {
						this.seePwd2 = 'img/WithdrawCash2.png';
						this.doSeePwd2 = true;
						this.pwdType2 = 'email';
					} else {
						this.seePwd2 = 'img/WithdrawCash1.png';
						this.doSeePwd2 = false;
						this.pwdType2 = 'password';
					}
				},
				checked: function() {
					$('#phoneAgree').prop('checked', 'checked');
				},
				register: function() {
					let username = $("#username").val().trim();
					let password = $("#password").val().trim();
					let password2 = $("#password2").val().trim();
					let recommendedUserName = $("#recommendedUserName").val().trim();
					if(!username) {
						$.toptip('帐号不能为空！', 'error');
						return false;
					}
					if(username.length < 6) {
						$.toptip('帐号最少输入6位！', 'error');
						return false;
					}
					if(!password) {
						$.toptip('密码不能为空！', 'error');
						return false;
					}
					if(password.length < 6) {
						$.toptip('请输入大于6位数的密码！', 'error');
						return false;
					}
					if(!password2) {
						$.toptip('确认密码不能为空！', 'error');
						return false;
					}
					if(password != password2) {
						$.toptip('两次输入的密码不一致！', 'error');
						return false;
					}
					if(!recommendedUserName) {
						$.toptip('推荐人用户名不能为空！', 'error');
						return false;
					}
					if(!$('#phoneAgree').prop('checked')) {
						$.toptip('请阅读并同意用户协议', 'error');
						return false;
					}
					let params = {
						"username": username,
						"password": rsaEncrypt(password),
						"repassword": rsaEncrypt(password2),
						"inviteCode": recommendedUserName,
						"type": 0
					}
					$(".button-fix").attr("disabled", true);
					$.ajax({
						type: "POST",
						url: ip + '/platform/user/regist.m',
						data: params,
						success: function(data) {
							if(data.statusCode == 0) {
								$.toptip("注册成功！", 1000, 'success');
								setTimeout(function() {
									window.location.href = "https://m.freeworl.com/apps/install.html?targetDir=NSC&tdsourcetag=s_pctim_aiomsg";
								}, 1000);
							} else {
								setTimeout(function() {
									$(".button-fix").attr("disabled", false);
								}, 1000);
								$.toptip(data.resultDesc, 1000, 'error');
							}
						},
						error: function(err) {
							setTimeout(function() {
								$(".button-fix").attr("disabled", false);
							}, 1000);
							$.toptip(err, 'error');
						}
					})
				}
			}
		});

		function getQueryValue(name) {
			// 创建正则表达式，这个表达式匹配以name开头或者&name开头，以&结尾或者就是name结尾
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			// 解码url
			var decodedUrl = decodeURI(window.location.search);
			// 匹配表达式，返回一个group数组
			var r = decodedUrl.substr(1).match(reg);
			// 数组下标2的元素就是所要截取的结果
			if(r != null) return unescape(r[2]);
			return null;
		}
	</script>

</html>